package com.lbd.dynamicCode.service.impl;

import com.lbd.base.service.BaseServiceImpl;
import com.lbd.dynamicCode.bean.MsgSendRecord;
import com.lbd.dynamicCode.dao.DynamicCodeRepository;
import com.lbd.dynamicCode.service.DynamicCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * Created by zzl on 2017/11/19.
 */
@Service
@Transactional
public class DynamicCodeServiceImpl extends BaseServiceImpl<MsgSendRecord, DynamicCodeRepository> implements DynamicCodeService{
    @Autowired
    DynamicCodeRepository dynamicCodeRepository;


    /**
     * 构建查询语句和参数
     *
     * @param record
     * @param parameter 参数(开始时间和结束时间)
     * @return
     */
    @Override
    public String buildJpql(MsgSendRecord record, Map<String, Object> parameter) {
        StringBuilder jpqlBuilder = new StringBuilder("  from  MsgSendRecord t   ");
        if (record != null) {
//            if (MsgBatch.getBeginTime()!=null&&MsgBatch.getEndTime()!=null) {
//                jpqlBuilder.append(" and  :beginTime>=t.beginTime and :endTime <= t.endTime");
//                parameter.put("beginTime", MsgBatch.getBeginTime());
//                parameter.put("endTime", MsgBatch.getEndTime());
//            }
          /* if(StringUtils.isNotBlank(MsgBatch.getName())){
               jpqlBuilder.append(" and  name like:name");
                parameter.put("name", "%"+MsgBatch.getName()+"%");
           }
           if(StringUtils.isNotBlank(MsgBatch.getShowPlatform())){
               jpqlBuilder.append(" and  showPlatform like:showPlatform");
               parameter.put("showPlatform", "%"+MsgBatch.getShowPlatform()+"%");
           }*/
        }
        return jpqlBuilder.toString();
    }

    /**
     * 根据ID查询MsgSendRecord
     *
     * @param id
     * @return
     */
    @Override
    public MsgSendRecord findById(String id) {
        MsgSendRecord record = dynamicCodeRepository.findOne(id);
        return record;
    }

    @Override
    public MsgSendRecord saveInfo(MsgSendRecord record) {
        return dynamicCodeRepository.save(record);
    }

    @Override
    public int updateInfo(MsgSendRecord record) {
        return dynamicCodeRepository.updateRecord(record.getShortLink(),record.getLandUrl(),record.getId());
    }
}
